var $annotation={
	xpcom:Components.classes["@mozilla.org/browser/annotation-service;1"].getService(Components.interfaces.nsIAnnotationService),
	set:function(bkid,desc){
		$annotation.xpcom.setItemAnnotation(bkid, "bookmarkProperties/description",desc, 0, 0);
	}
}
var $bookmark={
	folder:{
		add:function(name){
		//	var menuFolder = ; //Bookmarks menu folder
			return $bookmark.xpcom.createFolder($bookmark.xpcom.bookmarksMenuFolder, name, -1);
		},
		get:function(){
			var Connect=$bookmark.storage();
			var storageWrapper = Components.classes["@mozilla.org/storage/statement-wrapper;1"].createInstance(Components.interfaces.mozIStorageStatementWrapper);
			var statement=Connect.createStatement("SELECT * FROM moz_bookmarks where type='2'");
			storageWrapper.initialize(statement);
			var json="";
			while (storageWrapper.step()) {
				json=json+"{title:'"+storageWrapper.row["title"]+"',id:'"+storageWrapper.row["id"]+"'},";
			}
		//	return eval('['+json+']');
			return json;
		}
	},
	storage:function(){
		var file = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile);
		file.append("places.sqlite");
		var storageService = Components.classes["@mozilla.org/storage/service;1"].getService(Components.interfaces.mozIStorageService);
		return storageService.openDatabase(file);
	},
	xpcom:Components.classes["@mozilla.org/browser/nav-bookmarks-service;1"].getService(Components.interfaces.nsINavBookmarksService),
	bkid:function(url){
		return $bookmark.xpcom.getBookmarkIdsForURI($bookmark.objUrl(url),{});
	},
	add:function(url,title,tag,desc){
		if($bookmark.xpcom.isBookmarked($bookmark.objUrl(url))){return;}
		$bookmark.xpcom.insertBookmark($bookmark.xpcom.unfiledBookmarksFolder, $bookmark.objUrl(url),-1, title);
		$taging.add(url,tag)
		var id=this.bkid($bookmark.objUrl(url));
		if(desc){
			$annotation.set(id,desc);
		}
		return id;
	},
	objUrl:function(url){
		return Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService).newURI(url, null, null);
	},
	log: function(str) {
		Components.classes['@mozilla.org/consoleservice;1'].getService(Components.interfaces.nsIConsoleService).logStringMessage(str);
	},
};
var $taging={
	xpcom:Components.classes["@mozilla.org/browser/tagging-service;1"].getService(Components.interfaces.nsITaggingService),
	add:function(url,tag){
		$taging.xpcom.tagURI($bookmark.objUrl(url), tag);
	}
}